package com.cowin.inf.dao;

import com.cowin.base.Mapper;
import com.cowin.inf.model.KyVehicleQueue;
import com.cowin.inf.model.vo.KyVehicleQueueVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface KyVehicleQueueMapper extends Mapper<KyVehicleQueue> {


    /**
     * 功能描述: 获取队列第一个<br>
     *
     * @param queueType
     * @return: KyVehicleQueue
     * @since: 1.0.0
     * @Author:yuchao
     * @Date: 2019/11/28 16:20
     */
    @Select("select * from (select * from KY_VEHICLE_QUEUE order by id,SORT_CODE asc, CREATE_TIME desc) where QUEUE_TYPE= #{queueType} and WAIT_POINT= #{waitPoint} and rownum=1")
    KyVehicleQueue findQueueFirst(@Param("queueType") String queueType, @Param("waitPoint")String waitPoint);


    /**
     * 功能描述: 车辆 是否在锁定队列<br>
     *
     * @param queueType vin
     * @return:
     * @since: 1.0.0
     * @Author:yuchao
     * @Date: 2019/11/28 16:36
     */
    @Select("select * from KY_VEHICLE_QUEUE  where QUEUE_TYPE= #{queueType} and vin=#{vin}")
    KyVehicleQueueVo findIsInQueue(@Param("queueType") String queueType,@Param("vin")  String vin);


    /**
     * 功能描述: 过点成功 从队列中删除<br>
     *
     * @param
     * @return:
     * @since: 1.0.0
     * @Author:yuchao
     * @Date: 2019/11/28 17:17
     */
    @Delete("DELETE FROM KY_VEHICLE_QUEUE where vin=#{vin} and QUEUE_TYPE = #{queueType}")
    int remove(@Param("queueType") String queueType,@Param("vin")  String vin);

    /**
     * 功能描述: 修改队列等待点<br>
     *
     * @param
     * @return:
     * @since: 1.0.0
     * @Author:yuchao
     * @Date: 2020/3/13 11:54
     */
    @Update("UPDATE KY_VEHICLE_QUEUE set WAIT_POINT=#{waitPoint} where  QUEUE_TYPE= #{queueType} and vin=#{vin}")
    int updateWaitPoint(@Param("queueType") String queueType, @Param("vin") String vin, @Param("waitPoint") String waitPoint);

    /**
     * 功能描述: 查询系统参数配置 BDC出车数量<br>
     *
     * @return:
     * @since: 1.0.0
     * @Author:yuchao
     * @Date: 2019/12/5 9:59
     */
    @Select("SELECT PARAMETER_VALUE FROM TM_SYS_PARAMETER where PARAMETER_NAME = #{parameterName}")
    String  findBDCScopeNum(String parameterName);
}